
//
// 120312 - AH - (Garage).
// 120313 - AH - Made Serializable.
// 120515 - AH - RetrievedSerializable replaces deprecated
//               ConversationObjectSerializable.
//

package org.soekrat.server.serialization;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *   Describes chat output.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC)
 */
public final class ChatOutputSerializable implements Serializable 
{
  private static final long serialVersionUID=1366711210747088070L;

  private Date date=new Date();
  
  private List<RetrievedSerializable> retrieved=null; 
  
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public ChatOutputSerializable(){}
  
  /**
   * <p>
   *   Gets creation date.
   * </p>
   * @return Date.
   */
  public Date getDate(){ return date; }
  
  public ChatOutputSerializable addRetrieved(RetrievedSerializable r)
  {
    if (r==null)
    {
      throw new NullPointerException("r");
    }
      
    if (retrieved==null) retrieved=new ArrayList<RetrievedSerializable>();
      
    retrieved.add(r);
      
    return this;
  }
  
  @Override
  public String toString() 
  {
    StringBuilder sb=new StringBuilder();
    
    boolean first=true;
    if (date!=null)
    {
      sb.append("date=").append(date);
      first=false;
    }
    
    if (retrieved!=null)
    {
      if (!first) sb.append(", ");
      sb.append(retrieved);
    }
    
    return sb.toString();
  }
  
}
